package com.example.lib.server;

import com.example.lib.userinfo.FileUserInfoDAOImpl;
import com.example.lib.userinfo.UserInfo;

import java.util.List;

public class Register {

    public static String register(String username, String password) {
        if (username.contains(" ")) {
            // 用户名不能包含空格
            return "null";
        }
        FileUserInfoDAOImpl userInfoDAO = new FileUserInfoDAOImpl();

        List<UserInfo> userInfoList = userInfoDAO.getAllUserInfo();
        if (userInfoList != null) {
            for (UserInfo userInfo: userInfoList) {
                if (userInfo.getName().equals(username)) {
                    // 用户名已存在
                    return "existed";
                }
            }
        }
        userInfoDAO.addUserInfo(new UserInfo(username, password));
        return "success";
    }
}
